const request = (url = '', method = "POST", data = {}, contentType = 'form') => {
	uni.showLoading({
		title: '加载中',
		mask: true
	})
	let headers = {}
	if (contentType == 'json') {
		headers = {
			'content-type': 'application/json',
			// 'token': uni.getStorageSync('token') || ''
		}
	} else {
		headers = {
			'content-type': 'application/x-www-form-urlencoded;charset=utf-8;'
			// 'token': uni.getStorageSync('token') || ''
		}
	}
	return new Promise((resolve, reject) => {
		data = {
			...data,
			token:uni.getStorageSync('token')
		}
		uni.request({
			url: url,
			data: data,
			method: method || 'GET',
			header: headers,
			success: (res) => {
				uni.hideLoading()
				resolve(res.data)
				if (res.data.code == 201) {
					uni.showToast({
						title: res.data.message,
						icon: 'none'
					})
					setTimeout(() => {
						uni.switchTab({
							url: '/pages/tabbar/my/my'
						})
						uni.removeStorageSync('token')
					}, 1500)
				}
			},
			fail: (err) => {
				uni.hideLoading()
				uni.showToast({
					title: '数据请求失败',
					icon: 'none'
				})
				reject(err)
			}
		})
	})
}
export {
	request
}